//右侧时间
setInterval(function () {
  let month = document.querySelector(".month");
  let year = document.querySelector(".year");
  let weak = document.querySelector(".weak");
  month.innerHTML = str1; //替换内容为显示的时间
  year.innerHTML = str2; //替换内容为显示的时间
  weak.innerHTML = str3; //替�
}, 1000);

//生成时间对象，什么也不传，获取当前系统的时间
let D = new Date();

let nian = D.getFullYear(); //获取年
let yue = (D.getMonth() + 1).toString().padStart(2, 0); //获取月 0-11
let ri = D.getDate().toString().padStart(2, 0); //获取日
let xingqi = numOfChinese(D.getDay()); //获取星期几 0-6，0是星期日

// let shi = changeNum(D.getHours());      //获取小时
// let fen = D.getMinutes();     //获取分钟
// let miao = D.getSeconds();    //获取秒

/* 
    对数字进行调整
*/

//把星期的数字换成汉字
function numOfChinese(num) {
  let arr = ["日", "一", "二", "三", "四", "五", "六"];
  return arr[num];
}
//小时前面加上0
function changeNum(num) {
  if (num < 10) {
    return "0" + num;
  } else {
    return num;
  }
}
let str1 = `${yue}/${ri}`;
let str2 = `/${nian}`;
let str3 = `星期${xingqi}`;
// let str = '现在时间是' + nian + '年' + yue + "月" + ri + '日，星期' + xingqi + "  " + shi + '时' + fen + "分" + miao + "秒";
// let str = `${nian}/${yue}/${ri} , ${shi}:${fen}:${miao},${xingqi}`
// return str;
let articleEl = document.querySelector(".article")

// localStorage.setItem("token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYzMjMyNDVmNzU0MmEzYzA0ZmM3MmM1MSIsImlhdCI6MTY2MzI0NzUxMCwiZXhwIjoxNjYzNDIwMzEwfQ.EqHEQXJuhQX_eimzYzljyJcZrGzm3_8BaZ4rQh3V7Fg");

// console.log(articleEl);
// localStorage.setItem("token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYzMjE5N2JkOGMwZmQzMzNmNjQ2ZDE3YyIsImlhdCI6MTY2MzQ2NzUxOCwiZXhwIjoxNjYzNjQwMzE4fQ.PFHCP6iDvZzvk0BUZljrBV8REEqeYiH8Ui6UcHKt-tk");


// let eiJi = '';
getNotebooks();
async function getNotebooks() {
  // 发请求
  let res = await axios({
    method: "GET",
    url: "/api/diaryItem/homepage",
    params: {
      limit: 20,
      offset: 0,
    },
  });


  let dataS = res.data.data;

  //请求作者名字
  let res1 = await axios({
    method: "GET",
    url: "/api/user",
    params: {
      userId: '632197bd8c0fd333f646d17c'
    },
  });


  let userN = res1.data.data;
  // console.log(9898, userN);



  //请求日记图像
  let res3 = await axios({
    method: "GET",
    url: "/api/diarybook",

    params: {
      authorId: "632197bd8c0fd333f646d17c",
    },
  });
  // console.log(666, res3);
  let photo = res3.data.data.diarybooks;
  //获取日记名
  let res4 = await axios({
    method: "GET",
    url: "/api/diarybook",

    params: {
      authorId: "632197bd8c0fd333f646d17c",
    },
  });

  // console.log(666, res3);
  // let photo = res3.data.data.diarybooks;
  // console.log(888, photo);

  let notebooksLists = res4.data.data.diarybooks;
  for (let i = 0; i < notebooksLists.length; i++) {
    firstName = notebooksLists[i].title

  }


  // console.log(37, notebooksLists);


  let html = "";

  //存id

  for (const item of dataS) {
    html += `
     <div class="ayt">
        <img class="tuxiang" src="http://localhost:8000${userN.headphoto}" alt="">
              <div class="diary">
                <span class="ancut">${userN.username}</span>
                <span class="timeUP">${item.createAt}</span>
                <span class="diaryName">${firstName}</span>
                <div class="ct">
                  <img class="imge" src="http://localhost:8000${photo.coverPhoto}" alt="">
                  <p class="world">${item.content}</p>
                </div>
                <div class="raly"><a href="./reply.html"><button class="bbt" data-id='${item._id}'>回复</button></a></div>
                <div class="line1"></div>
                </div>
      </div>
     `;
    // console.log(38, item._id);
  }
  // console.log(html);
  articleEl.innerHTML = html;

  let btnEl = document.querySelector(".bbt");

  btnEl.onclick = function () {
    let buy = btnEl.getAttribute("data-id");

    // console.log(444, buy);

    // console.log(444, buy);


    window.localStorage.setItem("id", buy);
  };
}

//寂寞榜获取数据
let useEl = document.querySelector(".use");
grtUse();
async function grtUse() {
  // 发请求
  let res3 = await axios({
    method: "GET",
    url: "/api/user/atLoneliness",
    params: {},
  });


  let message = res3.data.data;
  console.log(985, message);
  html = "";
  for (const item of message) {
    html += `
       <li>
            <div class="user">
              <a class="tt" href="../../html/lk/user-diary.html">
                <img src="http://localhost:8000${item.headphoto}" alt="">
              </a>
              <a class="wz" href="../../html/lk/user-diary.html">
                <p>${item.username}</p>
              </a>
            </div>
          </li>
  `;
    useEl.innerHTML = html;
  }
}
